//
//  LSZBranchProfileViewController.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/30.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZBranchProfileViewController.h"

@interface LSZBranchProfileViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tableViewBranchProfile;
@property(nonatomic,strong) LSZThreeMeetingsContactManager* threeMeetingsContactManager;

@end

@implementation LSZBranchProfileViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden=YES;
    [self partyAffairsThirdMeetingOneClassGetContacts:self.id_id];
}
-(void)partyAffairsThirdMeetingOneClassGetContacts:(NSString *)id_id
{
    [LSZRequestDicData partyAffairsThirdMeetingOneClassGetContacts:id_id :^(BOOL isok, NSString * string, LSZThreeMeetingsContactManager * manager) {
        if (isok == YES) {
            self.threeMeetingsContactManager = manager;
            [self.tableViewBranchProfile reloadData];
        }else{
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZBranchProfileViewController"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }
    }];
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
-(void)addNotificationCenter
{
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZBranchProfileViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addNotificationCenter];
    [self.tableViewBranchProfile registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.tableViewBranchProfile registerClass:[LSZTotalNumberTableViewCell class] forCellReuseIdentifier:@"LSZTotalNumberTableViewCell"];
    [self.tableViewBranchProfile registerClass:[LSZDetailsOfEachTableViewCell class] forCellReuseIdentifier:@"LSZDetailsOfEachTableViewCell"];
    [self.tableViewBranchProfile registerClass:[LSZSummaryHeaderCell class] forHeaderFooterViewReuseIdentifier:@"LSZSummaryHeaderCell"];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(self.threeMeetingsContactManager.arrayData.count > 0){
        return self.threeMeetingsContactManager.arrayData.count+1;
    }else{
        return 0;
    }
 }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 40;
    }else{
        return 80;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    CGFloat height = [LSZSpecialPackaging getHeightOfText:ScreenWidth-20 height:ScreenHeight font:17 :self.summary]+20;
    return height+10;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    LSZSummaryHeaderCell * header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZSummaryHeaderCell"];
    CGFloat height = [LSZSpecialPackaging getHeightOfText:ScreenWidth-20 height:ScreenHeight font:17 :self.summary]+20;
    CGRect frame = header.viewBack.frame;
    frame.size.height = height;
    header.viewBack.frame = frame;
    
    CGRect frameLab = header.labelTitle.frame;
    frameLab.size.height = height-20;
    header.labelTitle.frame = frameLab;
    if (self.summary.length == 0) {
        header.labelTitle.text = @"暂无简介!";
    }else{
        header.labelTitle.text = self.summary;
    }
    return header;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0 ){
        LSZTotalNumberTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZTotalNumberTableViewCell" forIndexPath:indexPath];
        cell.labelTitle.text = [NSString stringWithFormat:@"总共%ld人",(long)self.threeMeetingsContactManager.arrayData.count];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        LSZDetailsOfEachTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZDetailsOfEachTableViewCell" forIndexPath:indexPath];
        LSZThreeMeetingsContactMg * mg = nil;
        mg = self.threeMeetingsContactManager.arrayData[indexPath.row-1];
        [cell.imageViewHeader sd_setImageWithURL:[NSURL URLWithString:mg.headUrl] placeholderImage:[UIImage imageNamed:@"默认"]];
        cell.labelName.text = mg.realName;
        cell.labelPosition.text = mg.job;
        cell.labelGender.text = [NSString stringWithFormat:@"性别:%@",mg.sex];
        cell.labelPhone.text = [NSString stringWithFormat:@"手机号:%@",mg.mobilePhone];
        
        
        CGFloat width = [LSZSpecialPackaging getsTheAdaptiveWidth:cell.labelName sizeMaxWidth:ScreenWidth]+10;
        CGRect frame = cell.labelName.frame;
        frame.size.width = width;
        cell.labelName.frame = frame;
        
        CGFloat widthPosition = [LSZSpecialPackaging getsTheAdaptiveWidth:cell.labelPosition sizeMaxWidth:ScreenWidth]+5;
        CGRect framePosition = cell.labelPosition.frame;
        framePosition.origin.x = CGRectGetMaxX(cell.labelName.frame)+5;
        framePosition.size.width = widthPosition;
        cell.labelPosition.frame = framePosition;
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
//    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
//    LSZThreeMeetingsContactMg * mg = nil;
//    mg = self.threeMeetingsContactManager.arrayData[indexPath.row];
//    cell.textLabel.text = mg.realName;
//    cell.textLabel.font = FONT_(14);
//    cell.textLabel.textColor = titleColorLSZ;
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    return cell;
}
-(UITableView *)tableViewBranchProfile
{
    if(_tableViewBranchProfile == nil){
        _tableViewBranchProfile = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,ScreenWidth,ScreenHeight-44-20) style:UITableViewStyleGrouped];
        _tableViewBranchProfile.delegate = self;
        _tableViewBranchProfile.dataSource = self;
        _tableViewBranchProfile.estimatedRowHeight=0;
        _tableViewBranchProfile.estimatedSectionFooterHeight =0;
        _tableViewBranchProfile.estimatedSectionHeaderHeight =0;
        [_tableViewBranchProfile setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewBranchProfile];
    }
    return _tableViewBranchProfile;
}


@end
